Home:ALL Converter>Laravel Eloquent update multiple rows with same value but different ID

Laravel Eloquent update multiple rows with same value but different ID

Ask Time:2020-02-24T00:52:28         Author:Radical_Activity

Json Formatter

I'm using Laravel 6 and Eloquent. I'm looking for a way to update a set of rows with a set value, each identified with a unique ID.

This is what I'm doing right now:

$ids = [3948, 1984, 7849, 4456, 394];
$value = false;

foreach ($ids as $id)
{
   User::where("id", $id)->update(["status" => $value]);
}

Is there a way to accomplish the same with only 1 query instead of 5?

Author:Radical_Activity,eproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/60364562/laravel-eloquent-update-multiple-rows-with-same-value-but-different-id
yy